<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <title>好“孕”来 - 登录</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
      background: linear-gradient(135deg, #fff9fb 0%, #fff5f7 100%);
      color: #333;
      min-height: 100vh;
      position: relative;
      overflow-x: hidden;
    }

    body::before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><path d="M50,50 Q100,20 150,50 T200,100 Q170,150 100,150 T0,100 Q30,50 50,50 Z" fill="rgba(255,182,193,0.1)"/></svg>');
      background-size: 300px;
      opacity: 0.3;
      z-index: -1;
    }

    .container {
      padding: 80px 20px 40px;
      max-width: 400px;
      margin: 0 auto;
    }

    .header {
      text-align: center;
      margin-bottom: 40px;
    }



    .app-icon {
      width: 90px;
      height: 90px;
      
      border-radius: 25px;
      display: flex;
      align-items: center;
      justify-content: center;
      margin: 0 auto 25px;
      font-size: 45px;
      color: white;
      box-shadow: 0 8px 20px rgba(255, 154, 158, 0.25);
     
    }

    .app-title {
      font-size: 28px;
      color: #5a2d3e;
      font-weight: 700;
      margin-bottom: 12px;
      letter-spacing: 0.5px;
    }

    .app-subtitle {
      font-size: 15px;
      color: #8a6d7c;
      line-height: 1.5;
    }

    .login-card {
      background: rgba(255, 255, 255, 0.85);
      border-radius: 25px;
      padding: 30px;
      box-shadow: 0 15px 35px rgba(0, 0, 0, 0.08);
      border: 1px solid rgba(255, 255, 255, 0.6);
      backdrop-filter: blur(12px);
    }

    .login-tabs {
      display: flex;
      margin-bottom: 30px;
      border-radius: 15px;
      background: rgba(255, 182, 193, 0.15);
      padding: 5px;
    }

    .tab-btn {
      flex: 1;
      padding: 14px;
      border: none;
      background: transparent;
      border-radius: 12px;
      font-size: 16px;
      cursor: pointer;
      transition: all 0.3s ease;
      color: #8a6d7c;
      font-weight: 500;
    }

    .tab-btn.active {
      background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
      color: white;
      box-shadow: 0 4px 15px rgba(255, 154, 158, 0.3);
    }

    .form-group {
      margin-bottom: 25px;
    }

    .form-label {
      display: block;
      font-size: 15px;
      color: #5a2d3e;
      margin-bottom: 10px;
      font-weight: 500;
    }

    .form-input {
      width: 100%;
      padding: 16px;
      border: 1px solid rgba(255, 182, 193, 0.4);
      border-radius: 15px;
      font-size: 16px;
      transition: all 0.3s ease;
      background: rgba(255, 255, 255, 0.7);
    }

    .form-input:focus {
      outline: none;
      border-color: #ff9a9e;
      box-shadow: 0 0 0 3px rgba(255, 154, 158, 0.2);
    }

    .login-btn {
      width: 100%;
      padding: 18px;
      background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
      color: white;
      border: none;
      border-radius: 15px;
      font-size: 17px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
      margin-top: 10px;
      box-shadow: 0 6px 20px rgba(255, 154, 158, 0.3);
      border: 1px solid rgba(255,255,255,0.4);
      letter-spacing: 0.5px;
    }

    .login-btn:hover {
      transform: translateY(-3px);
      box-shadow: 0 10px 25px rgba(255, 154, 158, 0.4);
    }

    .login-btn:active {
      transform: translateY(0);
    }

    .error-msg {
      color: #e74c3c;
      font-size: 13px;
      margin-top: 8px;
      display: none;
      padding-left: 5px;
    }

    .user-menu {
      display: none;
      padding: 20px;
    }

    .menu-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 20px;
      margin-bottom: 30px;
    }

    .menu-item {
      background: rgba(255, 255, 255, 0.85);
      border-radius: 20px;
      padding: 30px 20px;
      text-align: center;
      cursor: pointer;
      transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
      box-shadow: 0 8px 25px rgba(0, 0, 0, 0.06);
      border: 1px solid rgba(255, 255, 255, 0.5);
      backdrop-filter: blur(8px);
    }

    .menu-item:hover {
      transform: translateY(-8px) scale(1.03);
      box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
      border-color: rgba(255, 182, 193, 0.5);
    }

    .menu-icon {
      width: 65px;
      height: 65px;
      background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      margin: 0 auto 20px;
      font-size: 32px;
      color: white;
      box-shadow: 0 6px 15px rgba(255, 154, 158, 0.25);
      border: 2px solid rgba(255,255,255,0.5);
    }

    .menu-title {
      font-size: 17px;
      color: #5a2d3e;
      margin-bottom: 8px;
      font-weight: 600;
    }

    .menu-desc {
      font-size: 13px;
      color: #8a6d7c;
      line-height: 1.4;
    }

    .logout-btn {
      width: 100%;
      padding: 16px;
      background: rgba(255, 255, 255, 0.7);
      color: #d63384;
      border: 1px solid rgba(255, 182, 193, 0.4);
      border-radius: 15px;
      font-size: 16px;
      cursor: pointer;
      transition: all 0.3s ease;
      font-weight: 500;
      backdrop-filter: blur(5px);
    }

    .logout-btn:hover {
      background: rgba(255, 255, 255, 0.9);
      color: #b82c70;
    }

    @media (max-width: 480px) {
      .app-title {
        font-size: 24px;
      }
      
      .menu-grid {
        grid-template-columns: 1fr;
      }
    }
  </style>
</head>

<script src="user.js"></script>  <!-- 登录页面 1015本次修订-->

<body>
  <!-- 登录页面 -->
  <div id="loginPage" class="container">
    <div class="header">
	<!-- 1014修改 更换logo -->
      <div class="app-icon">  
        <img src="logo.png" alt="好孕来" style="width: 100%; height: 100%; object-fit: contain; border-radius: 25px;">
      </div>
      <div class="app-title">好"孕"来</div>
      <div class="app-subtitle">产职融合智能管理系统<br>让孕期工作与生活更安心</div>
    </div>

    <div class="login-card">
      <div class="login-tabs">
        <button class="tab-btn active" onclick="switchTab('user')">普通用户登录</button>
        <button class="tab-btn" onclick="switchTab('admin')">管理者登录</button>
      </div>

      <!-- 普通用户登录 -->
      <div id="userLogin" class="login-form">
        <div class="form-group">
          <label class="form-label">用户名</label>
          <input type="text" class="form-input" id="userUsername" placeholder="请输入姓名" value="孕某某">
          <div class="error-msg" id="userError"></div>
        </div>
        <div class="form-group">
          <label class="form-label">密码</label>
          <input type="password" class="form-input" id="userPassword" placeholder="请输入密码" value="haoyunlai">
          <div class="error-msg" id="userPasswordError"></div>
        </div>
        <button class="login-btn" onclick="login('user')">登录</button>
      </div>

      <!-- 管理者登录 -->
      <div id="adminLogin" class="login-form" style="display: none;">
        <div class="form-group">
          <label class="form-label">管理员账号</label>
          <input type="text" class="form-input" id="adminUsername" placeholder="请输入管理员账号" value="admin">
          <div class="error-msg" id="adminError"></div>
        </div>
        <div class="form-group">
          <label class="form-label">密码</label>
          <input type="password" class="form-input" id="adminPassword" placeholder="请输入密码" value="haoyunlai">
          <div class="error-msg" id="adminPasswordError"></div>
        </div>
        <button class="login-btn" onclick="login('admin')">登录</button>
      </div>
    </div>
  </div>

  <!-- 普通用户菜单 -->
  <div id="userMenu" class="container user-menu">
    <div class="header">
		<!-- 1014修改logo -->
      <div class="app-icon">
        <img src="logo.png" alt="好孕来" style="width: 100%; height: 100%; object-fit: contain; border-radius: 25px;">
      </div>
      <div class="app-title">欢迎，<span id="userName">-</span></div>
      <div class="app-subtitle">请选择您需要的服务</div>
    </div>

    <div class="menu-grid">
      <div class="menu-item" onclick="navigateToModule('智能业务管理')" style="grid-column:span 2;"> <!-- 界面显示调整 1015本次修订 -->        <div class="menu-icon">💼</div>
        <div class="menu-title">智能业务管理</div>
        <div class="menu-desc">任务管理、案源推送、审限监控</div>
      </div>
      <div class="menu-item" onclick="navigateToModule('暖心服务')">
        <div class="menu-icon">💖</div>
        <div class="menu-title">暖心服务</div>
        <div class="menu-desc">知识学习、医疗资源、心理支持</div>
      </div>
      <div class="menu-item" onclick="navigateToModule('园区服务')">
        <div class="menu-icon">🏢</div>
        <div class="menu-title">园区服务</div>
        <div class="menu-desc">母婴室、车位、营养餐</div>
      </div>
    </div>

    <button class="logout-btn" onclick="logout()">退出登录</button>
  </div>

	<script>
	/* ========== 1. 拉取 CSV 并解析 1015本次修订 ========== */
	const CSV_URL = 'https://haoyunlai-12345-1342611250.cos.ap-guangzhou.myqcloud.com/users.csv?t='+Date.now();

	// 把 CSV 文本解析成 {normalUsers:[],adminUsers:[]}
	function parseCSV(text) {
	  const normalUsers = [], adminUsers = [];
	  let section = '';
	  text.split(/\r?\n/).forEach(ln => {
		ln = ln.trim();
		if (ln === '【普通用户】') { section = 'normal'; return; }
		if (ln === '【管理者用户】') { section = 'admin'; return; }
		if (!ln || ln.startsWith('【')) return;
		const arr = ln.split(',');
		if (section === 'normal' && arr.length >= 8) {
		  normalUsers.push({
			username: arr[0].trim(),
			password: arr[1].trim(),
			name: arr[2].trim(),
			position: arr[3].trim(),
			department: arr[4].trim(),
			pregnancyStatus: arr[5].trim(),
			dueDate: arr[6].trim(),
			maternityLeave: arr[7].trim()
		  });
		}
		if (section === 'admin' && arr.length >= 5) {
		  adminUsers.push({
			username: arr[0].trim(),
			password: arr[1].trim(),
			name: arr[2].trim(),
			position: arr[3].trim(),
			department: arr[4].trim()
		  });
		}
	  });
	  return {normalUsers, adminUsers};
	}

	/* ========== 2. 网络 or 兜底 ========== */
	async function loadAccounts() {
	  try {
		const res = await fetch(CSV_URL);
		if (!res.ok) throw new Error('fetch err');
		const txt = await res.text();
		window.__validUsers = parseCSV(txt);
		console.log('[Login] 成功加载 CSV 账号');
	  } catch (e) {
		console.warn('[Login] CSV 加载失败，回落到 user.js 兜底', e);
		window.__validUsers = {
		  normalUsers: userConfig.normalUsers || [],
		  adminUsers:  userConfig.adminUsers  || []
		};
	  }
	}
	/* 立即执行，登录按钮真正点击时 __validUsers 已经就绪 */
	loadAccounts();

	/* ----------------------------------------------------------
	 * 冷启动控制：sessionStorage 里没有 loginSession=1 就一定停在登录页 1015本次修订
	 * ----------------------------------------------------------*/
	(function(){
	  const hasLocal   = !!localStorage.getItem('currentUser');
	  const hasSession = sessionStorage.getItem('loginSession') === '1';

	  // 先把两个最外层容器恢复到“初始登录状态”
	  document.getElementById('loginPage').style.display = 'block';
	  document.getElementById('userMenu').style.display = 'none';

	  if (hasLocal && hasSession) {
		// 会话未断，允许自动恢复欢迎页
		try {
		  const user = JSON.parse(localStorage.getItem('currentUser'));
		  document.getElementById('userName').textContent = user.name;
		  document.getElementById('loginPage').style.display = 'none';
		  document.getElementById('userMenu').style.display = 'block';
		} catch (e) {
		  console.warn('自动恢复登录态失败', e);
		}
	  }
	  // 否则页面自然就停在登录页，无需额外处理
	})();
	
	</script>

  <script>
    // 切换登录标签
    function switchTab(type) {
      const tabs = document.querySelectorAll('.tab-btn');
      tabs.forEach(tab => tab.classList.remove('active'));
      
      if (type === 'user') {
        document.getElementById('userLogin').style.display = 'block';
        document.getElementById('adminLogin').style.display = 'none';
        tabs[0].classList.add('active');
      } else {
        document.getElementById('userLogin').style.display = 'none';
        document.getElementById('adminLogin').style.display = 'block';
        tabs[1].classList.add('active');
      }
    }

    // 登录功能 1015本次修订
	function login(type) {
	  const isUser = (type === 'user');
	  const nameInput = document.getElementById(isUser ? 'userUsername' : 'adminUsername');
	  const pwdInput  = document.getElementById(isUser ? 'userPassword' : 'adminPassword');
	  const name = nameInput.value.trim();
	  const pwd  = pwdInput.value.trim();

	  // 清掉旧提示
	  document.querySelectorAll('.error-msg').forEach(el=>el.style.display='none');

	  if(!name){ showError(isUser,'userError','请输入用户名'); return; }
	  if(!pwd) { showError(isUser,'userPasswordError','请输入密码'); return; }

	  // 账号池
	  const pool = isUser ? window.__validUsers.normalUsers
						  : window.__validUsers.adminUsers;
	  const hit  = pool.find(u => u.username === name && u.password === pwd);

	  if(hit){
		 
		 
		//1016 管理者登录进入管理者模块  
		localStorage.setItem('currentUser', JSON.stringify(hit));
		if (type === 'admin') {
			window.location.href = 'guanli.html';
			return; // 跳转后立即返回，避免执行后续代码
		}  
		  
		  
		/* ===== 1. 缓存当前用户 ===== */
		// 根据用户名决定后续要加载的 CSV 文件名   1015本次修订
		const csvMap = {          // 普通用户 → csv 文件名（可继续扩展）
		  '涂明珏': 'zhineng_1.csv',  //王某某
		  '王鹤迪': 'zhineng_2.csv',  //张某某
		  '黄思怡': 'zhineng_3.csv'  //李某某
		};
		const csvFile = csvMap[hit.username] || 'zhineng.csv';   // 默认 fallback
		localStorage.setItem('currentUser', JSON.stringify({...hit, csvFile}));

	  /* ===== 2. 进入欢迎页 ===== */
	  document.getElementById('userName').textContent = hit.name;
	  document.getElementById('loginPage').style.display = 'none';
	  document.getElementById('userMenu').style.display = 'block';
	 }else{
		showError(isUser, isUser?'userError':'adminError',
				  isUser?'用户名或密码错误':'管理员账号或密码错误');
	  }

	  function showError(isUser,id,txt){
		const el = document.getElementById(id);
		el.textContent = txt;
		el.style.display = 'block';
	  }
	}
      

    // 导航到模块
    function navigateToModule(moduleName) {
      switch(moduleName) {
        case '暖心服务':
          window.location.href = 'nuanxin.html?from=userMenu'; // 返回到欢迎界面 1014本次修改
          break;
        case '园区服务':
          window.location.href = 'yuanqu.html?from=userMenu'; // 返回到欢迎界面 1014本次修改
          break;
        case '智能业务管理':
          window.location.href = 'zhineng.html?from=userMenu';  // 返回到欢迎界面 1014本次修改
          break;
      }
    }
	// 返回到欢迎界面 1014本次修改
	window.addEventListener('DOMContentLoaded', function () {
		if (window.location.hash === '#userMenu') {
			document.getElementById('loginPage').style.display = 'none';
			document.getElementById('userMenu').style.display = 'block';
		}
	});
	
	
    // 退出登录 1015本次修订
	function logout() {
	  localStorage.removeItem('currentUser');
	  sessionStorage.removeItem('loginSession');   // 关键：把会话标志也清掉

	  document.getElementById('userMenu').style.display = 'none';
	  document.getElementById('loginPage').style.display = 'block';
	  document.getElementById('userPassword').value = '';
	  document.getElementById('adminPassword').value = '';
	}

    // 回车键登录
    document.addEventListener('keypress', function(e) {
      if (e.key === 'Enter') {
        const userForm = document.getElementById('userLogin');
        const adminForm = document.getElementById('adminLogin');
        
        if (userForm.style.display !== 'none') {
          login('user');
        } else {
          login('admin');
        }
      }
    });

	// 页面加载完成后的初始化 1015本次修订
	document.addEventListener('DOMContentLoaded', function () {
	  restoreUserCard();          // 首次加载恢复用户名
	  /* 输入框焦点动画 */
	  const inputs = document.querySelectorAll('.form-input');
	  inputs.forEach(input => {
		input.addEventListener('focus', function () {
		  this.parentElement.style.transform = 'scale(1.02)';
		});
		input.addEventListener('blur', function () {
		  this.parentElement.style.transform = 'scale(1)';
		});
	  });
	});

	/* 浏览器回退时也会触发 pageshow（iOS/Android 都支持）*/
	window.addEventListener('pageshow', function () {
	  restoreUserCard();          // 回退欢迎页时再次把用户名填上
	});

	/* 把 localStorage 用户信息恢复到欢迎页 1015本次修订 */
	function restoreUserCard(){
	  const saved = localStorage.getItem('currentUser');
	  if (!saved) return;               // 没登录过，啥也不干
	  try {
		const user = JSON.parse(saved);
		document.getElementById('userName').textContent = user.name;
	  } catch (e) {
		console.warn('恢复用户卡片失败', e);
	  }
	}
	  
	  
  </script>
</body>
</html>